// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

int t, n, m;
const int N = 1e3+50;

int a[N][N];
int b[2][N][N], ans[N][N];

vector<int> dx[N], dy[N];

void disc(int a[], int n, vector<int> &disc) {
    // disc.clear();
    disc.resize(n);
    for (int i=0; i<n; ++i)
        disc[i] = a[i];
    sort(disc.begin(), disc.end());
    disc.resize(unique(disc.begin(), disc.end()) - disc.begin());
    for (int i=0; i<n; ++i) {
        a[i] = lower_bound(disc.begin(), disc.end(), a[i]) - disc.begin() + 1;
    }
}

int main(int argc, char const *argv[]) {
    // code
    scanf("%d%d", &n, &m);
    for (int i=0; i<n; ++i)
        for (int j=0; j<m; ++j)
            scanf("%d", &a[i][j]);
    for (int i=0; i<n; ++i) {
        static int t[N];
        memcpy(t, a[i], 4 * m);
        disc(t, m, dx[i]);
        memcpy(b[0][i], t, 4 * m);
    }

    for (int i=0; i<m; ++i) {
        static int t[N];
        for (int j=0; j<n; ++j)
            t[j] = a[j][i];
        disc(t, n, dy[i]);
        memcpy(b[1][i], t, 4 * n);
    }

    for (int i=0; i<n; ++i)
        for (int j=0; j<m; ++j) {
            int x1 = b[0][i][j], x2 = b[1][j][i];
            const vector<int> &d1 = dx[i], &d2 = dy[j];
            if (x1 > x2) {
                ans[i][j] = max(d1.size(), x1 - x2 + d2.size());
            } else
                ans[i][j] = max(x2-x1 + d1.size(), d2.size());
        }

    for (int i=0; i<n; ++i)
        for (int j=0; j<m; ++j)
            printf("%d%c", ans[i][j], j==m-1? '\n':' ');
    return 0;
}
